package net.esj.basic.core.view.interceptor;

import java.util.Map;

import javax.inject.Inject;

import net.esj.basic.core.engine.factory.bean.BeanFactory;
import net.esj.basic.service.filter.DataFilter;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class DataFilterInterceptor extends AbstractInterceptor {

	BeanFactory beanFactory;
	
	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		Map<String,DataFilter> map = beanFactory.getBeansByType(DataFilter.class);
		for(DataFilter filter : map.values()){
			filter.doFilter((Action) invocation.getAction());
		}
		return invocation.invoke();
	}

	@Inject
	public void setBeanFactory(BeanFactory beanFactory) {
		this.beanFactory = beanFactory;
	}

	
}
